﻿using Sabloane_de_proiectare.Factory;
using Sabloane_de_proiectare.Memento;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace Sabloane_de_proiectare
{
    public sealed partial class MainPage : Page
    {
        private GameTableViewModel gameTableViewModel;
        public MementoStates memento { get; set; }
        private int gridRows;
        private int gridColumns;
        private Grid grid;
        public MainPage()
        {
            this.InitializeComponent();
            gameTableViewModel = new GameTableViewModel();
            memento = new MementoStates();
        }
        public void onClickUndo(object sender, RoutedEventArgs rea)
        {
            gameTableViewModel.loadPreviousState();
            reload();
        }
        private void Grid_Loaded(object sender, RoutedEventArgs e)
        {
            grid = (Grid) sender;
            gridColumns = grid.ColumnDefinitions.Count;
            gridRows = grid.RowDefinitions.Count;
            for (int i = 0; i < gridRows; i++)
            {
                for (int j = 0; j < gridColumns; j++)
                {
                    grid.Children.Add(gameTableViewModel.getElementAt(i,j));
                }
            }
        }
        private void reload()
        {
            grid.Children.Clear();
            for (int i = 0; i < gridRows; i++)
            {
                for (int j = 0; j < gridColumns; j++)
                {
                    grid.Children.Add(gameTableViewModel.getElementAt(i, j));
                }
            }
        }
    }
}
